/*Copyright 2010 by Matt Van Der Westhuizen */

package org.chaoticengine.ast.model;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.core.Resolve;

/**
 * A reference to a TradeGood using only the name - for loading object
 * references to TradeGoods from the TradeGoodFactory.
 *
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
@Root(name="TradeGood")
public class TradeGoodReference implements TradeGood {
    @Attribute(name="name")
    protected String name = "";

    public TradeGoodReference(@Attribute(name="name") String name) {
        this.name = name;
    }

    public short getBasePrice() {
        throw new UnsupportedOperationException("TradeGoodReference should only be used to load TradeGoodImplementations.");
    }

    public int getId() {
        throw new UnsupportedOperationException("TradeGoodReference should only be used to load TradeGoodImplementations.");
    }

    public String getName() {
        return(name);
    }

    @Resolve
    public TradeGood substitute() {
        return(TradeGoodFactory.getInstance().getTradeGood(name.toLowerCase()));
    }
}
